package cn.taobaoke.restful.controller;

import cn.taobaoke.restful.service.DataSourceService;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author bjyangzuo
 * @since 2017-05-11 07:08
 */
@RestController
@RequestMapping("/api/datasources")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class DataSourceController extends BaseController {

    @PutMapping
    public Result addDataSource(@RequestBody Map<String, Object> data) {
        dataSourceService.addDataSourceByDomain(data.get("datasource").toString());
        return wrapVoid();
    }

    @DeleteMapping("/{datasource}")
    public Result removeDataSource(@PathVariable String datasource) {
        dataSourceService.removeDataSourceByDomain(datasource);
        return wrapVoid();
    }

    private final @NonNull
    DataSourceService dataSourceService;
}
